package com.goldcn.sys.service;

import com.goldcn.sys.dao.GcnSysRolePageFunctionMapper;
import com.goldcn.sys.model.GcnSysRolePageFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;
import java.util.UUID;


@Component
public class SysRolePageFunctionService {  
	@Autowired
	GcnSysRolePageFunctionMapper gcnSysRolePageFunctionMapper;

    @Transactional
    public void saveAll(Collection<GcnSysRolePageFunction> sysRolePageFunctions){
        for (GcnSysRolePageFunction sysRolePageFunction : sysRolePageFunctions) {
        	if(sysRolePageFunction.getID()!=null && sysRolePageFunction.getID()!=""){ 
        		gcnSysRolePageFunctionMapper.updateByPrimaryKeySelective(sysRolePageFunction);
    		}else{
    			sysRolePageFunction.setID(UUID.randomUUID().toString().toUpperCase());
				gcnSysRolePageFunctionMapper.insertSelective(sysRolePageFunction);
    		}
        }
    }

    @Transactional
    public void deleteByID(Collection<GcnSysRolePageFunction> sysRolePageFunctions){
		for (GcnSysRolePageFunction sysRolePageFunction : sysRolePageFunctions) {
			gcnSysRolePageFunctionMapper.deleteByPrimaryKey(sysRolePageFunction.getID());
		} 
    }

	public int deleteByRoleID(String roleID){
		return gcnSysRolePageFunctionMapper.deleteByRoleID(roleID);
	}

	void insertBatch(List<GcnSysRolePageFunction> list){
		gcnSysRolePageFunctionMapper.insertBatch(list);
	}


	public List<String> getUserRolePage(List<String> roleIds){
		return gcnSysRolePageFunctionMapper.findRolePage(roleIds);
	}

}
